package com.mb.common.constants;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.binary.Base64;

/**
 * API 常量
 *
 * @author michael.li
 * @create 2018-03-24 下午3:24
 **/
public class APIConstants {
    //成功
    public static final String success = getMSG("0","成功");
    //Json格式化错误
    public static final String parseError = getMSG("10001","序列化失败");

    //通用异常
    public static final String commError = getMSG("90000","发生异常");
    //签名
    public static final String legalSignError = getMSG("20001","签名不一致");
    //超时
    public static final String legalTimeStampError = getMSG("20002","请求超时");

    //发送次数超限
    public static final String smsMaxTimes = "30001";
    public static final String smsMaxTimesMsg = "今日发送次数超限";
    public static final String smsMaxTimesError = getMSG(smsMaxTimes,smsMaxTimesMsg);

    //验证码不正确
    public static final String verfiyCodeErr = "30002";
    public static final String verfiyCodeErrMsg = "验证码错误";
    public static final String verfiyCodeError = getMSG(verfiyCodeErr,verfiyCodeErrMsg);

    /**
     * 交易状态
     */
    public enum HttpTradeStatus {
        succ(0, "成功"),
        fail(1, "失败");

        private int code;
        private String msg;

        private HttpTradeStatus(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }


    /**
     * 支付状态
     */
    public enum PayStatus{
        succ(0,"支付成功"),
        fail(90001,"支付失败");

        private int code;
        private String msg;

        private PayStatus(int code,String msg){
            this.code = code;
            this.msg = msg;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }




    /**
     * 支付交易状态
     */
    public enum TradeState{
        unPay(0,"未支付"),
        succ(1,"支付成功"),
        refund(2,"退款"),
        closed(3,"交易关闭"),
        userPaying(4,"用户支付中"),
        payError(5,"支付失败"),
        tradeFinished(6,"交易结束，不可退款");

        private int code;
        private String msg;

        private TradeState(int code,String msg){
            this.code = code;
            this.msg = msg;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }



    /**
     * 支付方式
     */
    public enum PayMode{
        wxpay("1","微信"),
        alipay("2","支付宝");

        private String code;
        private String msg;

        private PayMode(String code,String msg){
            this.code = code;
            this.msg = msg;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }

    /**
     * 微信支付方式
     */
    public enum WxPayType{
        app("1","APP"),
        qrcode("2","扫码"),
        h5("3","H5"),
        mp("4","公众号");

        private String code;
        private String msg;

        private WxPayType(String code,String msg){
            this.code = code;
            this.msg = msg;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }


    /**
     * 支付宝支付方式
     */
    public enum AliPayType{
        app("1","APP"),
        qrcode("2","扫码"),
        h5("3","H5");

        private String code;
        private String msg;

        private AliPayType(String code,String msg){
            this.code = code;
            this.msg = msg;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }


    /**
     * 短信类型
     */
    public enum SmsType{
        verifiyCode(1,"验证码"),
        auth(2,"认证"),
        order(3,"订单确认");

        private int code;
        private String msg;

        private SmsType(int code,String msg){
            this.code = code;
            this.msg = msg;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }


    /**
     * 推送消息类型
     */
    public enum PushMsgType{
        order(1,"订单消息"),
        other(2,"其他消息");

        private int code;
        private String msg;

        private PushMsgType(int code,String msg){
            this.code = code;
            this.msg = msg;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }


    /**
     * 推送类型
     */
    public enum PushType{
        notify(1,"通知"),
        message(2,"透传");

        private int code;
        private String msg;

        private PushType(int code,String msg){
            this.code = code;
            this.msg = msg;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }


    /**
     * 透传消息类型
     */
    public enum TransMessageType{
        weexEvent(1,"weexEvent");

        private int code;
        private String msg;

        private TransMessageType(int code,String msg){
            this.code = code;
            this.msg = msg;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }


    /**
     * weex全局事件名称
     */
    public enum WeexEventName{
        orderListRefresh("orderListRefresh","刷新订单");

        private String code;
        private String msg;

        private WeexEventName(String code,String msg){
            this.code = code;
            this.msg = msg;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }


    /**
     * 短信发送状态
     */
    public enum SmsSendStatus{
        sended(0,"已发送"),
        success(1,"成功"),
        fail(-1,"失败");

        private int code;
        private String msg;

        private SmsSendStatus(int code,String msg){
            this.code = code;
            this.msg = msg;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }


    /**
     *
     * 转换公共返回
     * @param code
     * @param msg
     * @return
     */
    private static String getMSG(String code, String msg) {
        try {
            JSONObject jo = new JSONObject();
            jo.put("code", code);
            jo.put("msg", msg);
            return new String(Base64.encodeBase64(jo.toJSONString().getBytes()));
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }



    /**
     * redis消息对列
     */
    public enum RedisTopic{
        WX_MSG("topic-mp-001","微信消息"),
        PUSH_MSG("topic-mp-002","推送消息");

        RedisTopic(String code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        private String code;
        private String msg;

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }

    /**
     * @description: 订单状态
     * @author: TimothyZz
     * @date: 2018/4/8 14:34
     */
    public enum OrderStatus {
        STANDING(1, "待派单"),
        ASSIGNED(2, "已派单，待接单"),
        RECEIVED(3, "已接单，待上门"),
        FORWARD(4, "已上门"),
        CUSTOMER_RECEIVED(5, "用户确认接单"),
        RETURN(6, "退单"),
        PAY(7, "用户待支付"),
        PAID(8, "用户已支付"),
        FINISH(9, "订单完成"),
        PAY_SALE(10, "下单方待支付"),
        PAID_SALE(11, "下单方已支付"),
        SUSPENDED(12, "挂单");

        private int code;
        private String msg;

        OrderStatus(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }



}
